package com.dycong.common.dataStructuresAndAlgorithms;



import java.util.*;

/**
 * Created by Duke on 2016/11/16.
 */
public class MyCollection {

    Map<String, List<String>> adiWords = new HashMap<>();
    Set<String>set=new HashSet<>();



    public void init() {
        long t = System.currentTimeMillis();
        for (int i = 0; i < 99; i++) {
            List<String> list = new LinkedList<>();
            for (int j = 0; j < 2; j++) {
                String str = Chapter1.getRandomString(j);
                list.add(str);
            }
            adiWords.put(String.valueOf(i), list);
            String str1=Chapter1.getRandomString(8);
            set.add(str1);
        }
        System.out.println(System.currentTimeMillis() - t + "--init()");
    }

    /**
     * @see  map的get()方法：当map里存在null值时get()方法得到的null-->当map存在null值时get(key)得到null不能说明map里没有该key，此时要用containsKey(key)
     * map是null的key只可以有一个，是null的value只可以有一个，key和value不可以同时为null
     */

    public void testMapEntrySet() {
        long t = System.currentTimeMillis();
        for (Map.Entry<String, List<String>> entry : adiWords.entrySet()) {
            List<String> words = entry.getValue();
        }
        System.out.println(System.currentTimeMillis() - t + "--entrySet()");
    }

    public void testMapKeySet() {
        long t = System.currentTimeMillis();
        for (String s : adiWords.keySet()) {
            adiWords.get(s);
        }
        System.out.println(System.currentTimeMillis() - t + "--keySet()");
    }


    public void testMapIterator() {
        long t = System.currentTimeMillis();
        Iterator iterator = adiWords.values().iterator();
        while (iterator.hasNext()) {
            List<String> list = (List<String>) iterator.next();
        }
        System.out.println(System.currentTimeMillis() - t + "--iterator()");
    }

    public void map(){
        Map<Integer,Integer>map=new HashMap<>();
        map.put(null,null);
        map.put(null,1);
        map.put(1,null);
        map.put(1,null);
        map.put(1,null);
//        map.put(1,1);
//        map.put(1,2);
//        map.put(1,3);
        System.out.println(map.get(1));
    }
    public void testValueOf() {
       Collection<List<String>> listValues=adiWords.values();
    }

    public void testSet(){
        Iterator<String>iterator=set.iterator();
        while (iterator.hasNext()){
            System.out.println(iterator.next() + "--iterator" + Thread.currentThread().getName());
        }
        for (String s:set){
            System.out.println(s+"----for"+Thread.currentThread().getName());
        }

    }



    public void test() {
//        print();
//        testValueOf();
//        testSet();
        /*
        ThreadPoolService threadPoolService=new ThreadPoolService();
        threadPoolService.submit(()->testSet());
        threadPoolService.submit(()->testSet());
        */

        /*
        ExecutorService executorService = Executors.newCachedThreadPool();
        executorService.submit(()->testSet());
        executorService.submit(()->testSet());
        */
        /*
        testMapEntrySet();
        testMapKeySet();
        testMapIterator();
        */
//        map();
    }
}
